package edu.unindra.elearning;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DifferentDate {

	/**
	 * @param args
	 * @throws ParseException
	 */
	public static void main(String[] args) throws ParseException {
		String tanggalAwal = "15-09-2014";
		DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
		Date tanggal = (Date) dateFormat.parse(tanggalAwal);
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(tanggal);
		Calendar cal2 = Calendar.getInstance();
		cal2.setTime(new Date());
		System.out.println(daysBetween(cal1, cal2));

		if (daysBetween(cal1, cal2) > 30.0) {
			System.out.println("Move File");
		} else {
			System.out.println("Keep File");
		}
	}

	public static long daysBetween(Calendar tanggalAwal, Calendar tanggalAkhir) {
		long bedaHari = 0;
		Calendar tanggal = (Calendar) tanggalAwal.clone();
		while (tanggal.before(tanggalAkhir)) {
			tanggal.add(Calendar.DAY_OF_MONTH, 1);
			bedaHari++;
		}
		return bedaHari;
	}
}
